package com.gzz.orchid.main.facade.rsocket;

import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.stereotype.Component;

/**
 * https://blog.csdn.net/weixin_43114209/article/details/144877741
 * 客户端订阅推送
 */
@Component
public class SensorClient {

    private final RSocketRequester rSocketRequester;

    public SensorClient(RSocketRequester rSocketRequester) {
        this.rSocketRequester = rSocketRequester;
    }

    public void listenToSensorData() {
        rSocketRequester.route("sensor-data")
                .retrieveFlux(Integer.class) // 获取通知流
                .doOnNext(data -> System.out.println("Received sensor data: " + data))
                .subscribe();
    }
}

